package com.ry.est.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.ry.est.dao.BrandDao;
import com.ry.est.dto.BrandDTO;
import com.ry.est.entity.Brand;
import com.ry.est.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ry.est.dto.BrandDTO;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 商品品牌业务组件
 */
@Service
public class BrandServiceImpl implements BrandService {
    @Autowired
    private BrandDao brandDao;


    @Override
    public List<BrandDTO> listBrandByIdsAndStatus(List<Long> ids, Integer status) {
        if (ObjectUtil.isEmpty(ids)){
            return new ArrayList();
        }

        List<Brand> brands = brandDao.listBrandByIdsAndStatus(ids, status);
        List<BrandDTO> brandDTOS = brands.stream().map(entity -> {
            BrandDTO brandDTO = new BrandDTO();
            brandDTO.setId(entity.getId());
            brandDTO.setBrandName(entity.getBrandName());
            brandDTO.setLogo(entity.getLogo());

            return brandDTO;
        }).collect(Collectors.toList());

        return brandDTOS;
    }
}
